<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建管理员信息</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="username">
        </div>
        <div class="layui-form-mid">默认密码123</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="realname">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="phone">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="email" name="email">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="create">建号</button>
        </div>
    </div>
</form>
<script src="/layui/layui.js"></script>
<script>
    //var $ //全局变量
    layui.use(['form'], () => {
        const form = layui.form;
        $ = layui.$; //没有使用类型定义，就是全局变量

        form.on('submit(create)', (data) => {

            //ajax
            $.ajax({
                url: '/admin/add',
                data: data.field,
                type: 'post',
                dataType: 'json',
                success(result) {
                    if (result.code == 0) {
                        parent.layer.msg('账号创建成功', {icon: 6});
                        parent.layer.closeAll("iframe");
                    } else {
                        layer.msg(result.msg, {icon: 5});
                    }
                },
                error() {
                    layer.msg('请求失败', {icon: 5});
                }
            });

            //阻止表单自动提交
            return false;
        });

    });
</script>
</body>
</html>